package com.neusoft.neuiotms.dcam.workflow.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcam.workflow.dto.RukuSLDTO;
import com.neusoft.neuiotms.dcam.workflow.service.RukuSLService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "资产入库工单")
@RestController
@RequestMapping(value = "/api/w/workflow/rukusl")
public class RukuSLController {

    @Autowired
    private RukuSLService rukuSLService;

    @ApiOperation("分页查询入库单")
    @GetMapping("/p")
    public PageResultDTO<RukuSLDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.rukuSLService.search(pageable, searchable));
    }

    @ApiOperation("新增资产入库申请")
    @PostMapping
    public ResultDTO<RukuSLDTO> create(@RequestBody final RukuSLDTO dto,
            final UserBean user) {
        return ResultDTO.success(this.rukuSLService.create(dto, user));
    }

    @ApiOperation("查看资产入库申请")
    @GetMapping("/{workOrderNum}/{taskId}")
    public ResultDTO<RukuSLDTO> details(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.rukuSLService.detail(workOrderNum, taskId, user));
    }

    @ApiOperation("查看资产入库申请")
    @GetMapping("/{id}")
    public ResultDTO<RukuSLDTO> details(@PathVariable final Long id) {
        return ResultDTO.success(this.rukuSLService.detail(id));
    }

}
